import formJs from "./regexDetail.js"; //新增弹框配置项
import publicForm from "@/components/public/el-form.vue"; //弹框form
import TableData from "@/components/public/el-tables"; //主页面列表


import {
    getStationmachineByfMachineid, //查看详情
    getTotalAmountDetail, //主页面列表详情接口

} from "@/api/request.js";

export default {
    props: [
        "dialogVisible",
        "dialogTitle",
       
        "currentRow",
        "fCompanyid",
        "fCompanyname",
        "modelType",
        "isclose"
    ],
    data() {
        return {
            table_config: formJs.table_config, 
            tableData: [], //材料用量列表
            formObj:formJs.formObj,
            formData:{},
            navigatepageNums: null, //是否显示分页
            queryCriteriaData: {}, //分页
            aggregateData:null,
            tableList: {
                companyid: "", // 施工标段id
                taskNumber: "",
                page: 1, // 当前页码
                pageSize: 4, // 每页显示条数
              },
              baseData:null,
              isShow:false

        };
    },
    components: {
        publicForm,
        TableData

    },
    watch: {
        dialogVisible: {
            handler(newVal) {
                if (newVal) {
                    this.visible = newVal;
                }
            },
            immediate: true,
        },
        dialogTitle: {
            handler(newVal) {
                if (newVal) {
                    this.title = newVal;
                }
            },
            immediate: true,
        },
        modelType: {
            handler(newVal) {
                if (newVal) {
                    this.modelTypes = newVal;
                }
            },
            immediate: true,
        },
    

        currentRow: {
            handler(newVal) {
                if (newVal) {
                    this.currentDetail = newVal;
                    this.tableList.taskNumber = this.currentDetail.F_ProduceTaskNumber;
                    this.baseData = this.currentDetail;
                    if (this.statusNum != 1) {
                        this.getDetail({
                         
                            machineId: this.currentDetail.F_MachineId 
                        }) // currentRow
                    }
                }
            },

            immediate: true,
        },
        fCompanyid: {
            handler(newVal) {
                if (newVal) {

                    this.fCompanyids = newVal
                    this.tableList.companyid = this.fCompanyids;

                }
            },
            immediate: true,
        },
        fCompanyname: {
            handler(newVal) {
                if (newVal) {
                    this.fCompanynames = newVal

                }
            },
            immediate: true,
        },

    },
    created() {
        window.addEventListener("resize", this.getHeight);
        this.getHeight();
    }, //获取页面高度自适应：

    destroyed() {
        window.removeEventListener("resize", this.getHeight);
        this.getHeight();
    },

    mounted() {
        this.userInfo = JSON.parse(sessionStorage.getItem("monitorBack-userInfo"));

        this.btnShow = true

        
        
       
        if (this.statusNum == 7) { //查看
            this.btnShow = false
            this.disabled = true;
           
            this.isEdit = true
           
        }
        this.getHeight();
    },
    methods: {
        // 选择工程部位
        refreshList() {},
        
        
        getHeight() {
            var h = document.documentElement.clientHeight; //获取页面可见高度
            this.dialogHeight = h * 0.76 + "px";
        },
       
        closeDialog() {
            this.$emit("close");
        },
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
          },
          indexMethod(index) {
            return index + 1 + (this.tableList.page - 1) * 4; // page是当前的页码，size是页码容量
          },
          handleCurrentChange(val) {
            this.tableList.page = val;
            this.tableList.companyid = this.fCompanyids;
            getTotalAmountDetail(this.tableList).then((res) => {
              if (res.errcode == 0) {
                console.log(res.data);
                var that = this;
                that.tableData = res.data.pageInfo.list;
                this.queryCriteriaData = res.data.pageInfo; //分页信息
                this.navigatepageNums =
                  this.queryCriteriaData.navigatepageNums.length;
              } else {
                this.$message.error(res.msg);
              }
            });
          },
      
     


        // 详情
        getDetail(obj) {
            this.loading=true;
            getStationmachineByfMachineid(obj)
                .then((res1) => {
                    if (res1.errcode == 0) {
                        this.loading = false;
                        this.aggregateData = [
                            res1.data.yjQmpMsStationmachine.fParm1,
                            res1.data.yjQmpMsStationmachine.fParm2,
                            res1.data.yjQmpMsStationmachine.fParm3,
                            res1.data.yjQmpMsStationmachine.fParm4,
                            res1.data.yjQmpMsStationmachine.fParm5,
                          ];
                          this.isShow = true;
                          this.tableList.page = 1;
                          getTotalAmountDetail(this.tableList).then((res) => {
                            if (res.errcode == 0) {
                              var that = this;
                              that.loadingEditDialog = false;
                              that.dialogEditVisible = true;
                              console.log(res.data.dischargeinfoList);
                              that.tableData = res.data.pageInfo.list;
                              this.queryCriteriaData = res.data.pageInfo; //分页信息
                              this.navigatepageNums =
                                this.queryCriteriaData.navigatepageNums.length;
                            } else {
                              this.$message.error(res.msg);
                            }
                          });
                    } else {
                        this.$message.error(res1.msg);
                        this.loading = false;
                        console.log("接口报错");
                    }
                })
                .catch((error) => {
                    console.log("拌合站设置编辑报错", error);
                });

        },
  

    },
};